{% extends "domain_page.html" %}

{% block extra_media %}
	{{ block.super }}
	<!-- Javascripts and associated styles -->
	<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.tooltip.js"></script>
	<link rel="stylesheet" href="{{ STATIC_URL }}css/jquery.tooltip.css" />
	<script type="text/javascript">
		<!--
		$(document).ready(function() {
			// viz options tooltips
			$('#options-list a.form-tooltip').tooltip({
				track: true,
				delay: 0,
				showURL: false,
				extraClass: "fixed-width"
			});

			$('#options form').submit(function() {
				$('#analysis-text').hide();
				$('#analysis-progress').show();

				var form = $('#options form');
				form.unbind('submit');
				var formData = form.serialize();

				var i = 0;
				var rqst = $.ajax({
					url: "",
					type: "POST",
					data: formData,
					dataType: "html",
					xhrFields: {
						onprogress: function(e) {
							$('#progress-log').html(e.target.responseText);
							$("#progress-log").scrollTop($("#progress-log")[0].scrollHeight);
						}
					},
					success: function() {
						var el = $('#progress-log div').last();
						if (el.hasClass('loglevel-error') || el.hasClass('loglevel-critical')) {
							$('#analysis-error').html('There was an error analyzing {{ name_obj }}.  We\'ve been notified of the problem and will look into fixing it.  Please <a href="">try again</a> later.');
						} else {
							setTimeout(function () { document.location = "../dnssec/"; }, 2000);
						}
					},
					error: function() {
						form.submit();
					}
				});

				return false;
			});
		});
		-->
	</script>
{% endblock %}
{% block dnssec_options %}{% endblock %}

{% block page_content %}
	<div id="analysis-text">
	{% if error_msg %}
		<p class="form-error">
		{{ error_msg }}
		</p> 
	{% else %}
		<p>
		{% if name_obj.analysis_end %}
		<span class="domain">{{ name_obj }}</span> was last analyzed on {{ name_obj.analysis_end|date }} UTC (<abbr class="timeago" title="{{ name_obj.analysis_end|date:"c" }}">{{ name_obj.updated_ago_str }} ago</abbr>).  To re-analyze the data, please click &quot;Analyze&quot; below.  This process may take several minutes.
		{% else %}
		<span class="domain">{{ name_obj }}</span> has not been analyzed before. To analyze this domain name, please click &quot;Analyze&quot; below.  This process may take several minutes.
		{% endif %}
		</p>
	{% endif %}
	<fieldset id="options">
	<form action="" method="post">
		<p id="analysis-submit">
			<input type="submit" class="button" value="Analyze" />
		</p>
		<ol id="options-list" class="analysis-options">
			{% for field in analyze_form %}
			<li>
				{{ field }}
			</li>
			{% endfor %}
		</ol>
	</form>
	</fieldset>
	</div>

	<div id="analysis-progress">
		<p>Please be patient while we analyze <span class="domain">{{ name_obj }}</span>.</p>
		<img alt="progress bar" src="{{ STATIC_URL }}images/progress.gif" />
		<div id="progress-log">
		</div>
		<p id="analysis-error" class="form-error">
		</p> 
	</div>
{% endblock %}
